<?php 
if(KT!='KhiThe') exit;
class productNew_controller extends productNew_model{
	
	public function __construct(){
		
		global $lang;
		
		$lang['url_base'] = url_base;	
		$this->path_cur = dirname(__FILE__);	
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
		parent::addObject('khithe_images');
		
		$this->lang = $lang;
	}
	public function index()
	{	
		$resultHtml ='';
		$file_cache =$this->path_cur.'/cache/'.dir_lang.'_product.xhtml';
		if(!file_exists($file_cache) || file_exists($file_cache) && ( filemtime($file_cache)+time_cache <= time() ) || caching==true)
		{
			$strModule = parent::khithe_display_template(dirname(__FILE__).'/productNew');
			$arrBlockHtml = $this->khithe_getBlockHtml($strModule);
			
			$arrRowNew = parent::get_product_top(12);
			
			if($arrRowNew>0){
				foreach ( $arrRowNew as $row_new ){
											
					if($row_new["PriceSpecial"]>0){
						$specialPrice = ($row_new["Price"]!=0?number_format($row_new["Price"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"]:$this->lang['Call']);
						$Price = number_format($row_new["PriceSpecial"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"];
						$PriceVal = $row_new["PriceSpecial"]/$this->lang["rate"];
					}else{
						$Price = ($row_new["Price"]!=0?number_format($row_new["Price"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"]:$this->lang['Call']);
						$PriceVal = ($row_new["Price"]!=0?$row_new["Price"]/$this->lang["rate"]:0);
						$specialPrice = '';	
					}
					$fileImg = path_base.'/uploads/products/'.$row_new['Picture'];			
					$fileThumbImg = path_base.'/uploads/products/cache/'.$row_new['Picture'];
					if(!is_file($fileThumbImg) && is_file($fileImg))
					{
						$this->setIMG($fileImg);
						$this->resizeImage(200, 180, 'auto');
						$this->saveImage($fileThumbImg);
					}
					$ThumbImg = url_base.'uploads/products/cache/'.$row_new['Picture'];
					if(!is_file($fileThumbImg)){
						$ThumbImg =url_base.'uploads/products/cache/logo.png';
					}
								   
				   $resultHtml .= $this->khithe_assign($arrBlockHtml['new'], array(
						'Title_full'=>$row_new["Title"],
						'Title_short'=>$row_new["Title"],
						'url_proNew'=>url_base.(parent::seo_list_parent(categorys,NULL,$row_new['CategoryID'])).$row_new['SeoKey'].'.html',
						'ThumbImg'=>$ThumbImg,
						'Price'=>$Price,
						'price-primary-val'=>$PriceVal,
						'product-id'=>$row_new["ID"],
						'specialPrice'=>$specialPrice,
						'url_cart'=>url_base.'shoppingcarts/add/'.$row_new["ID"],
					));	
				   
				}
				$resultHtml = $this->khithe_assignBlock($strModule, array('htmlnew'=>$resultHtml));
			}	
			$strModule = parent::khithe_assign($resultHtml, $this->lang);
			
			file_put_contents($file_cache,$strModule);
			
			return $strModule;
		
		} /* Doc Cache */
		else{
			$strModule = file_get_contents($file_cache);
			return $strModule;
		
		}
	}
	


}
?>